﻿using Microsoft.Extensions.DependencyInjection;
using SCZS.Example.Core.AutoMapper;
using SCZS.Example.Core.ConsulExtend.ClienExtend;
using SCZS.Example.Core.ConsulExtend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;

namespace SCZS.Example.Core.ServiceExtensions
{
    public static class ConsulSetup
    {
        public enum DispatcherType
        {
            /// <summary>
            /// 轮询
            /// </summary>
            Polling,
            /// <summary>
            /// 权重
            /// </summary>
            Weight,
            /// <summary>
            /// 平均
            /// </summary>
            Average

        }

        public static void AddConsulSetup(this IServiceCollection services, IConfiguration configuration, DispatcherType dispatcherType = DispatcherType.Polling)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.Configure<ConsulClientOption>(configuration.GetSection("ConsulClientOption"));
            switch (dispatcherType)
            {
                case DispatcherType.Polling:
                    services.AddTransient<AbstractConsulDispatcher, PollingDispatcher>();
                    break;
                case DispatcherType.Weight:
                    services.AddTransient<AbstractConsulDispatcher, WeightDispatcher>();
                    break;
                case DispatcherType.Average:
                    services.AddTransient<AbstractConsulDispatcher, AverageDispatcher>();
                    break;
                default:
                    break;
            }

        }
    }
}
